﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AmorCanino.Web.Models.Models;
using AmorCanino.Exceptions;

namespace AmorCanino.Web.Models.Services
{
    public class PetService : BaseService, IPetService
    {
        public Pet getPetById(int petId)
        {
            var db = new AmorCaninoDBDataContext();
            var pet = db.Animals.SingleOrDefault(p => p.AnimalId == petId && p.Visible);

            if (pet == null) throw new BusinessRuleException("No encontrado") { ExceptionType = BusinessRuleEnum.DataNotFound };

            return new Pet() {
                BirthDate = pet.BirthDate,
                PetId = pet.AnimalId,
                PetName = pet.Name,
                RaceId = pet.RaceId,
                ReceName = pet.Race.RaceName,
                UserId = pet.UserId,
                IsForAdoption = pet.IsForAdoption,
                IsForMate = pet.IsForMate,
                Visible = true,
                Vaxins = pet.Vaxins,
                Discapacities = pet.Discapacities,
                OtherPictures = db.PetRelatedPictures.Where(related => related.AnimalId == petId).Select(related => related.PictureID).ToList()
            };
        }
    }
}